/*
 * @Author: raoyonggang 11886335+ryg321@user.noreply.gitee.com
 * @Date: 2023-11-24 15:55:54
 * @LastEditors: raoyonggang 11886335+ryg321@user.noreply.gitee.com
 * @LastEditTime: 2024-04-16 11:30:58
 * @FilePath: \v9\src\mixins\index.js
 * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
 */
import { debounce, throttle } from "@/utils/debounce.js"

export const mixins = {
  data() {
    return {
      borderHeight: 500,
      tableHeightStyle: { background: "#f6f8f9", color: "#333333" }, // 表头颜色 
      hash: window.location.hash,  // 页面路径
      tableWidth: JSON.parse(localStorage.getItem('tableWidth')) || {}, // 表格的宽度
    }
  },
  mounted() {
    let form = document.getElementById('form')
    form && form.addEventListener('keyup', (e) => {
      if (e.keyCode == 13) {
        this.listenEnter()
      }
    })
  },
  methods: {
    // 获取当前表格可展示的高度
    getNumerical(num) {
      // 获取当前可视区域的高度
      let height = document.documentElement.clientHeight
      // 将可视区域的高度减去各个边距、边框、元素高度等等
      this.$nextTick((i) => {
        this.borderHeight = height - num - 46
      })
    },
    // 监听键盘的回车键功能
    listenEnter: debounce(function () {
      this.startGetting()
    }, 500),
    // 处理表格列宽度修改
    changeTableWidth(newWidth, oldWidth, column, event) {
      let key = window.location.hash + column.property // 保存的key
      let tableWidth = Object.assign(this.tableWidth, { [key]: newWidth })
      localStorage.setItem('tableWidth', JSON.stringify(tableWidth))
      for (const refName in this.$refs) {
        const ref = this.$refs[refName];
        // 判断是否是table实例
        if (ref && ref.doLayout) {
          ref.doLayout();
        }
      }
    },
  }
}